<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>煤炭管理系统</title>
    <#include "../base/base-css.ftl">

    <link rel="stylesheet" href="/static/css/member.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <#include "../base/main-header.ftl">

    <#include "../base/main-left.ftl">
    <div class="layui-body">
        <!-- 内容主体区域  -->
        <div class="site-title">
            <fieldset>
                <legend>
                    <a class="site-title-text">用户管理</a>
                </legend>
                <div id="add-member">
                    <a href="/addMember"><button class="layui-btn layui-btn-radius layui-btn-default">添加用户</button></a>
                </div>
            </fieldset>
        </div>
        <div class="table-box">
        <table class="layui-table" lay-size="lg">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>姓名</th>
                    <th>用户名</th>
                    <th>部门</th>
                    <th>角色</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            <#list users as user>
                <tr>
                    <td>${user.userId!"未知"}</td>
                    <td>${user.nickName!"未知"}</td>
                    <td>${user.username!"未知"}</td>
                    <td>${user.deptName!"未知"}</td>
                    <td>${user.roleName!"未知"}</td>
                    <#if user.userId ==  Session["user"].userId >
                    <td><a href="/person">查看</a>&nbsp;&nbsp;&nbsp; </td>
                    <#else>
                        <td>
                            <a href="/updateMember?id=${user.userId}">修改</a>&nbsp;&nbsp;&nbsp;
                            <a href="#" class="delete-btn">删除</a>&nbsp;&nbsp;&nbsp;
                            <a href="/updateMPassword?id=${user.userId}">重置密码</a>
                        </td>
                    </#if>

                </tr>

            </#list>
            </tbody>
        </div>
        </table>
    </div>
    <#include "../base/main-footer.ftl">
</div>

<#include "../base/base-js.ftl">

<script>
    layui.use(['layer', 'form', 'element', 'jquery'], function () {
        let layer = layui.layer, form = layui.form, $ = layui.jquery;
        $(".delete-btn").click(function () {
            var that = this
            layer.confirm('确认删除用户?', function(index){
                 var id = $(that).parent().parent().children().first().text()
                $.ajax({
                    type: "POST",
                    url: "/deleteMember.do?id="+id,
                    success: function (data) {
                        if (data.isSuccess){
                            layer.msg("删除成功")
                            setTimeout('window.location.reload()', 500);
                        } else {
                            layer.msg(data.msg)
                        }
                    }
                });

            });
            return false
        })
    });
</script>
</body>
</html>